{extend name="public/base" /}

{block name="title"}
<title>系统配置</title>
{/block}

{block name="pjax_container"}
<section class="content-header">
    <h1>系统配置</h1>
    <ol class="breadcrumb">
        <li class="active"><i class="fa fa-dashboard"></i> 系统配置</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <form class="form-horizontal" method="POST" action="{:url('edit')}" onsubmit="return false" >
                <div class="nav-tabs-custom">
                    <ul class="nav nav-tabs">
                        <li class="pull-right"><a href="javascript:history.back(-1)" class="btn btn-sm" style="padding:10px 2px;"> </a></li>
                    </ul>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">顶部轮播图片</label>
                        <div class="col-sm-7 upload-box">
                            <div class="image-box clear">
                                {volist name="$data['BannelArr']" id="v"}
                                <section class="image-section">
                                    <div class="image-shade"></div>
                                    <div class="image-delete"></div>
                                    <img class="image-show" src="{$v}" />
                                    <input name="bannel[]" value="{$v}" type="hidden" />
                                </section>
                                {/volist}
                                <section class="upload-section">
                                    <div class="upload-btn"></div>
                                    <input type="file" name="file" set-name="bannel" id="upload-input" value=""/>
                                </section>
                            </div>
                        </div>
                    </div>



                    <div class="form-group">
                        <label class="col-sm-2 control-label">签到二维码</label>
                        <div class="col-sm-7 upload-box" style="padding-top:7px;">
                            <a href="javascript:show_code();">点击查看</a> 实时<span style="color:red;">生成</span>/<span style="color:red;">刷新</span>最新签到二维码
                        </div>
                    </div>


                    <div class="form-group">
                        <label class="col-sm-2 control-label">客服二维码</label>
                        <div class="col-sm-7 my_uploads" style="border:1px solid blanchedalmond;">
                            <div class="child_my_uploads" style="margin-bottom:30px;">
                                <input class="form-control" type="hidden" name="server_qrcode" value="{$data.server_qrcode}"/>
                                <a href="{$data.server_qrcode}" target="_blank"><img src="{$data.server_qrcode}" style="width:100px;height:100px;"/></a>
                                <input type="file" name="file" class="layui-upload-file" id="myupload">
                            </div>
                        </div>
                    </div>
                    <!--<div class="form-group">-->
                        <!--<label class="col-sm-2 control-label">首页四大奖项简述</label>-->
                        <!--<div class="col-sm-7">-->
                            <!--公益奖 <input type="text" name="reward_desc[]" value="{$data.reward.j1}" style="width: 604px;"/> <br/><br/>-->
                            <!--健康奖 <input type="text" name="reward_desc[]" value="{$data.reward.j2}" style="width: 604px;"/> <br/><br/>-->
                            <!--排行奖 <input type="text" name="reward_desc[]" value="{$data.reward.j3}" style="width: 604px;"/> <br/><br/>-->
                            <!--参与奖 <input type="text" name="reward_desc[]" value="{$data.reward.j4}" style="width: 604px;"/> <br/>-->
                        <!--</div>-->
                    <!--</div>-->
                    <!--<div class="form-group">-->
                        <!--<label class="col-sm-2 control-label">奖励明细</label>-->
                        <!--<div class="col-sm-7"><textarea class="form-control" name="reward_details">{$data.reward.content}</textarea></div>-->
                    <!--</div>-->
                    <!--<div class="form-group">
                        <label class="col-sm-2 control-label">签到token</label>
                        <div class="col-sm-7"><input class="form-control" type="text" value="{$data.token}" disabled="disabled"/></div>
                    </div>-->

                    <!--<div class="form-group">-->
                        <!--<label class="col-sm-2 control-label">楼盘介绍</label>-->
                        <!--<div class="col-sm-7"><textarea class="form-control" name="houses_info">{$data.houses_info}</textarea></div>-->
                    <!--</div>-->
                    <div class="form-group">
                        <label class="col-sm-2 control-label">参赛规则和活动说明</label>
                        <div class="col-sm-7"><textarea class="form-control" name="points_desc">{$data.points_desc}</textarea></div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">公益基金</label>
                        <div class="col-sm-7"><input type="number" name="fund" value="{$data.fund}"/></div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">核销密码</label>
                        <div class="col-sm-7"><input type="text" name="verification_code" value="{$data.verification_code}"/></div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">注册起止时间</label>
                        <div class="col-sm-7">
                            <input type="date" name="reg_start_time" value="{$data.RegStartTimeStr}"> 至
                            <input type="date" name="reg_end_time" value="{$data.RegEndTimeStr}">
                        </div>
                    </div>
                    <div class="box-footer">
                        <div class="col-sm-2"></div>
                        <div class="col-sm-7">
                            <div class="btn-group pull-right">
                                <button type="submit" class="btn btn-info pull-right submits" data-loading-text="&lt;i class='fa fa-spinner fa-spin '&gt;&lt;/i&gt; 提交">提交</button>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</section>
<script type="application/javascript">
    KindEditor.create('textarea[name="reward_details"]',{
        width : '100%',   //宽度
        height : '320px',   //高度
        resizeType : '0',   //禁止拖动
        allowFileManager : false,   //允许对上传图片进行管理
        uploadJson : '{:url("File/kind_editor_upload")}',   //文件上传地址
        urlType : 'domain',   //带域名的路径
        formatUploadUrl: true,   //自动格式化上传后的URL
        autoHeightMode: false,   //开启自动高度模式
        afterBlur: function () { this.sync(); }   //同步编辑器数据
    });
    KindEditor.create('textarea[name="points_desc"]',{
        width : '100%',   //宽度
        height : '320px',   //高度
        resizeType : '0',   //禁止拖动
        allowFileManager : false,   //允许对上传图片进行管理
        uploadJson : '{:url("File/kind_editor_upload")}',   //文件上传地址
        urlType : 'domain',   //带域名的路径
        formatUploadUrl: true,   //自动格式化上传后的URL
        autoHeightMode: false,   //开启自动高度模式
        afterBlur: function () { this.sync(); }   //同步编辑器数据
    });
    KindEditor.create('textarea[name="houses_info"]',{
        width : '100%',   //宽度
        height : '320px',   //高度
        resizeType : '0',   //禁止拖动
        allowFileManager : false,   //允许对上传图片进行管理
        uploadJson : '{:url("File/kind_editor_upload")}',   //文件上传地址
        urlType : 'domain',   //带域名的路径
        formatUploadUrl: true,   //自动格式化上传后的URL
        autoHeightMode: false,   //开启自动高度模式
        afterBlur: function () { this.sync(); }   //同步编辑器数据
    });

    $("#upload-input").ajaxImageUpload({
        url: "{:url('File/store')}", //上传的服务器地址
        // data: { name:'勾国印' },
        data:{},
        maxNum: 5, //允许上传图片数量
        zoom: false, //允许放大
        allowType: ["gif", "jpeg", "jpg", "bmp",'png','zip'], //允许上传图片的类型
        maxSize :2, //允许上传图片的最大尺寸，单位M
        callbackFieldName:'saveName',
        before: function () {
            // alert('上传前回调函数');
        },
        success:function(data){
            // alert('上传成功回调函数');
            // console.log(data);
        },
        error:function (e) {
            // alert('上传失败回调函数');
            // console.log(e);
        }
    });

    // 点击查看签到二维码
    layui.use(['layer', 'upload'], function(){
        var layer = layui.layer;
        layui.upload({
            elem: '#myupload',
            url: "{:url('File/store')}",
            success: function(res){
                if(res.err == 0){
                    $("input[name=server_qrcode]").val(res.data.saveName);
                    $(".child_my_uploads a").attr('href', res.data.saveName);
                    $(".child_my_uploads img").attr('src', res.data.saveName);
                }
            },
            before: function(input){
                $('.layui-upload-button form').submit(function(event){
                    event.stopPropagation();
                });
            }
        });
    });
    function show_code(){
        interval_index = setInterval("ajax_sign_qrcode()", 1000);
        layer.open({
            type: 1,
            title:"签到二维码",
            area: ['400px', '400px'],
            shade:1,
            shadeClose:true,
            content: "<img class=\"image-show\" src=\"{$data.sign_qrcode}\" style='width:100%;height:100%;' />",
            end: function(index, layero){
                clearInterval(interval_index);
            }
        });
    }

    var ajax_return = 1;
    var interval_index = '';
    // 定时请求签到二维码
    function ajax_sign_qrcode() {
        var is_show_code = $('.layui-layer-content').html();
        var rand = Math.ceil(Math.random()*10)+new Date().getTime();
        var url = "{:url('ajax_sign_qrcode')}";
        if(is_show_code && ajax_return){
            ajax_return = 0;
            $.ajax({
                type:'get',
                url:url,
                timeout:2000,
                dataType:'json',
                success:function(data){
                    var url_a = data.code +'?rand='+rand;
                    var code_html = "<img class='image-show' src='"+url_a+"' style='width:100%;height:100%;'/>";
                    $('.layui-layer-content').html(code_html);
                },
                error : function(xhr,textStatus){
                    layer.alert('请求超时，请关闭二维码后重新打开');
                    clearInterval(interval_index);
                },
                complete:function(xhr, textStatus){
                    ajax_return = 1;
                }
            });
        }
    }


</script>
{/block}